package com.gethb.prod.service.impl;
import java.util.List;
import javax.annotation.Resource;

import com.gethb.data.dao.KLineMapper;
import com.gethb.data.mdo.TickerDo;
import com.gethb.prod.vo.KlineDataInVo;
import com.gethb.pub.utils.KLineDataUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.gethb.data.mdo.KlinesDo;
import com.gethb.prod.service.IGetKlineService;

@Component("getKlineService")
public class GetKlineServiceImpl implements IGetKlineService {

//    private static final Logger LOG = LoggerFactory.getLogger(GetKlineServiceImpl.class);



//    @Resource
//    KLineMapper klineMapper;// 接口

    @Override
    public TickerDo getTicker(String symbol) throws Exception {
      return KLineDataUtils.requestTicker(symbol);
    }

    @Override
    public List<KlinesDo> getList(KlineDataInVo inVo) throws Exception {

//        if (inVo.getPeriod().endsWith("min")) {
//            if (inVo.getPeriod().equals("1min")) {
//                ArrayList<KlinesDo> tempList = new ArrayList<>();
//                HashMap<Long,KlinesDo> cacheMap = KLineDataUtils.cacheMap.get(inVo.getSymbol());
//                cacheMap.keySet()
//                        .stream().sorted(Comparator.reverseOrder())
//                        .limit(inVo.getSize())
//                        .forEach((e) -> {
//                            tempList.add(cacheMap.get(e));
//                        });
//                return tempList;
//            }
//
//        } else if (inVo.getPeriod().endsWith("hour")) {
//
//        } else if (inVo.getPeriod().endsWith("day")) {
//
//        } else if (inVo.getPeriod().endsWith("week")) {
//
//        } else if (inVo.getPeriod().endsWith("mon")) {
//
//        } else if (inVo.getPeriod().endsWith("year")) {
//
//        }
//        if ("min".endsWith())

//        , 5min, 15min, 30min, 60min, 4hour, 1day, 1mon, 1week, 1year
//        inVo.getPeriod().

        int size = Integer.valueOf(inVo.getSize());
        List<KlinesDo> list = KLineDataUtils.requestList(inVo.getSymbol(), inVo.getPeriod(), size);
        return list;
    }
}
